package crm.util;

import java.sql.ResultSet;
import java.util.HashMap;
import crm.dbcoon.DBConnect;

public class GetBaseParam {
	
	/**
	 * 根据id获取政治面貌
	 * @param id
	 * @return
	 */
	public static String getPolityById(int id ) {
		DBConnect dbConnect = new DBConnect();
		ResultSet rs = null;
		String polityName = "";
		String sql = "select polityName from param_polity where id='"+id+"'";
		dbConnect.prepareStatement(sql);
		try {
			rs = dbConnect.executeQuery();
			if(rs.next()){
				polityName = rs.getString("polityName");
			}
			return polityName;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return polityName;
		}finally{
			dbConnect.close();
		}
	}
	
	/**
	 * 获取所有的政治面貌供选择
	 * @return
	 */
	public static HashMap getAllPolities(){
		HashMap polities = new HashMap();
		DBConnect dbConnect = new DBConnect();
		String sql = "select * from param_polity order by id";
		ResultSet rSet = null;
		dbConnect.prepareStatement(sql);
		try {
			rSet = dbConnect.executeQuery();
			while(rSet.next()){
				int key = rSet.getInt("id");
				String value = rSet.getString("polityName");
				polities.put(key, value);
			}
			return polities;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}finally{
			dbConnect.close();
		}
	}
	
	/**
	 * 根据id获取民族
	 * @param id
	 * @return
	 */
	public static String getNationById(int id ) {
		DBConnect dbConnect = new DBConnect();
		ResultSet rs = null;
		String nationName = "";
		String sql = "select nationName from param_nation where id='"+id+"'";
		dbConnect.prepareStatement(sql);
		try {
			rs = dbConnect.executeQuery();
			if(rs.next()){
				nationName = rs.getString("nationName");
			}
			return nationName;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return nationName;
		}finally{
			dbConnect.close();
		}
	}
	/**
	 * 获取所有的民族供选择
	 * @return
	 */
	public static HashMap getAllNations(){
		HashMap polities = new HashMap();
		DBConnect dbConnect = new DBConnect();
		String sql = "select * from param_nation order by id";
		ResultSet rSet = null;
		dbConnect.prepareStatement(sql);
		try {
			rSet = dbConnect.executeQuery();
			while(rSet.next()){
				int key = rSet.getInt("id");
				String value = rSet.getString("nationName");
				polities.put(key, value);
			}
			return polities;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}finally{
			dbConnect.close();
		}
	}
	/**
	 * 根据id获取省份
	 * @param id
	 * @return
	 */
	public static String getProvinceById(int id ) {
		DBConnect dbConnect = new DBConnect();
		ResultSet rs = null;
		String provinceName = "";
		String sql = "select provinceName from param_province where id='"+id+"'";
		dbConnect.prepareStatement(sql);
		try {
			rs = dbConnect.executeQuery();
			if(rs.next()){
				provinceName = rs.getString("provinceName");
			}
			return provinceName;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return provinceName;
		}finally{
			dbConnect.close();
		}
	}
	/**
	 * 获取所有的省份供选择
	 * @return
	 */
	public static HashMap getAllProvinces(){
		HashMap polities = new HashMap();
		DBConnect dbConnect = new DBConnect();
		String sql = "select * from param_province order by id";
		ResultSet rSet = null;
		dbConnect.prepareStatement(sql);
		try {
			rSet = dbConnect.executeQuery();
			while(rSet.next()){
				int key = rSet.getInt("id");
				String value = rSet.getString("provinceName");
				polities.put(key, value);
			}
			return polities;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}finally{
			dbConnect.close();
		}
	}
	/**
	 * 根据id获取职位
	 * @param id
	 * @return
	 */
	public static String getPositionById(int id ) {
		DBConnect dbConnect = new DBConnect();
		ResultSet rs = null;
		String position = "";
		String sql = "select position from param_position where id='"+id+"'";
		dbConnect.prepareStatement(sql);
		try {
			rs = dbConnect.executeQuery();
			if(rs.next()){
				position = rs.getString("position");
			}
			return position;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return position;
		}finally{
			dbConnect.close();
		}
	}
	/**
	 * 获取所有的职位供选择
	 * @return
	 */
	public static HashMap getAllPostions(){
		HashMap polities = new HashMap();
		DBConnect dbConnect = new DBConnect();
		String sql = "select * from param_position order by id";
		ResultSet rSet = null;
		dbConnect.prepareStatement(sql);
		try {
			rSet = dbConnect.executeQuery();
			while(rSet.next()){
				int key = rSet.getInt("id");
				String value = rSet.getString("position");
				polities.put(key, value);
			}
			return polities;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}finally{
			dbConnect.close();
		}
	}
	
	/**
	 * 获取所有的意向供选择
	 * @return
	 */
	public static HashMap getAllIntentions(){
		HashMap polities = new HashMap();
		DBConnect dbConnect = new DBConnect();
		String sql = "select * from param_intention order by id";
		ResultSet rSet = null;
		dbConnect.prepareStatement(sql);
		try {
			rSet = dbConnect.executeQuery();
			while(rSet.next()){
				int key = rSet.getInt("id");
				String value = rSet.getString("intention");
				polities.put(key, value);
			}
			return polities;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return null;
		}finally{
			dbConnect.close();
		}
	}
	/**
	 * 根据id获取意向
	 * @param id
	 * @return
	 */
	public static String getIntentionById(int id ) {
		DBConnect dbConnect = new DBConnect();
		ResultSet rs = null;
		String position = "";
		String sql = "select position from param_intention where id='"+id+"'";
		dbConnect.prepareStatement(sql);
		try {
			rs = dbConnect.executeQuery();
			if(rs.next()){
				position = rs.getString("intention");
			}
			return position;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return position;
		}finally{
			dbConnect.close();
		}
	}
	public static String getIntentionById(String id ) {
		DBConnect dbConnect = new DBConnect();
		ResultSet rs = null;
		String position = "";
		String sql = "select intention from param_intention where id='"+id+"'";
		dbConnect.prepareStatement(sql);
		try {
			rs = dbConnect.executeQuery();
			if(rs.next()){
				position = rs.getString("intention");
			}
			return position;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return position;
		}finally{
			dbConnect.close();
		}
	}
	
	/**
	 * 根据id获取阶段
	 */
	public static String getStageById(int id ) {
		DBConnect dbConnect = new DBConnect();
		ResultSet rs = null;
		String position = "";
		String sql = "select stage from param_recepitstage where id='"+id+"'";
		dbConnect.prepareStatement(sql);
		try {
			rs = dbConnect.executeQuery();
			if(rs.next()){
				position = rs.getString("stage");
			}
			return position;
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
			return position;
		}finally{
			dbConnect.close();
		}
	}
	/**
	 * 获取所有的阶段供选择
	 * @return
	 */
	
	public static HashMap getAllRecepitStages() {
	     DBConnect dbConnect =new DBConnect();
	     ResultSet rs = null;
	     HashMap stages = new HashMap();
	     String sql = "select * from param_recepitstage";
	     dbConnect.prepareStatement(sql);
	     try {
			rs = dbConnect.executeQuery();
			while(rs.next()){
				int id = rs.getInt("id");
				String stage = rs.getString("stage");
				stages.put(id, stage);
			}
		} catch (Exception e) {
			// TODO: handle exception
			e.printStackTrace();
		}finally{
			dbConnect.close();
		}
		return stages;
	}
	
	
	
	


}
